package day13_net.com.itheima.d3_udp2;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class Server {
    public static void main(String[] args) throws Exception {
        System.out.println("服务器启动成功。。。");
        DatagramSocket socket = new DatagramSocket(10086);
        byte[] buffer = new byte[1024 * 64];
        DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
        while ( true){
            socket.receive( packet);
            int len = packet.getLength();
            String msg = new String(buffer, 0, len);
            System.out.println("msg = " + msg);

            InetAddress ip = packet.getAddress();
            System.out.println("ip.getHostAddress() = " + ip.getHostAddress());
            System.out.println("packet.getPort() = " + packet.getPort());

        }
    }
}
